package com.dev.ac.web.client;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dev.ac.AcApplication;
import com.dev.ac.common.Const;
import com.dev.ac.common.Result;
import com.dev.ac.entity.AApplication;
import com.dev.ac.entity.AUser;
import com.dev.ac.service.AActiveService;
import com.dev.ac.service.AApplicationService;
import com.dev.ac.service.AUserService;
import com.dev.ac.util.JwtUtil;
import com.dev.ac.vo.MyActiveVo;
import com.dev.ac.vo.UserNewPassword;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/user")
public class UserStudentController {
    @Autowired
    AActiveService aActiveService;
    @Autowired
    AApplicationService aApplicationService;
    @Autowired
    AUserService aUserService;
    @Autowired
    JwtUtil jwtUtil;

    /**获取所有活动信息**/
    @GetMapping("/getAllAActiveInformation")
    public Result GetAllAActiveInformation(Integer pageNum){
        return Result.success(aActiveService.GetAllAActiveInformationService(pageNum));
    }
    /**活动报名添加**/
    @GetMapping("/EvenRegistration")
    public Result EvenRegistration(Integer activeId, HttpServletRequest httpServerRequest)
    {
        return Result.success(aActiveService.EvenRegistrationService(activeId,httpServerRequest));
    }
    /**查询我参加的活动**/
    @PostMapping ("/myParticipationActive")
    public Result MyParticipationActive(@Validated @RequestBody MyActiveVo myActiveVo, HttpServletRequest httpServletRequest)
    {
        System.out.println("======================");
        System.out.println(myActiveVo);
        return Result.success(aActiveService.MyParticipationActivieService(myActiveVo,httpServletRequest));
    }

    /**删除我的活动**/
    @GetMapping("/deletemyactive")
    public Result DeleteMyActive(Integer id,HttpServletRequest httpServletRequest){
        return Result.success(aApplicationService.DeleteMyActiveService(id,httpServletRequest));
    }
/***获取我的总分数信息**/
@GetMapping("/selecttotalscore")
public Result SelectTotalScore(HttpServletRequest httpServletRequest){
    return Result.success(aActiveService.SelectTotalScoreService(httpServletRequest));

}
/****密码修改**/
@PostMapping("/newpassword")
public Result NewPassword(@Validated @RequestBody UserNewPassword newPassword,HttpServletRequest httpServletRequest){
    return Result.success(aUserService.NewPasswordService(newPassword,httpServletRequest));
}
/**获取用户信息**/
@GetMapping("/getuserinformation")
public Result GetUserInformation(HttpServletRequest httpServletRequest){
    String token = httpServletRequest.getHeader("token");
    Claims claimByToken = jwtUtil.getClaimByToken(token, Const.GRADE_USER);
    Integer subject = Integer.valueOf(claimByToken.getSubject());
    AUser aUser = aUserService.getOne(new QueryWrapper<AUser>()
            .eq("id", subject));
    return Result.success(aUser);
}
/***学生信息更新**/
@PostMapping("/updateinformation")
public Result UpdateInformation(@Validated @RequestBody AUser aUser,HttpServletRequest httpServletRequest){
    return Result.success(aUserService.UpdateInformationService(aUser,httpServletRequest));
}
}
